package py.com.alfa.escriba.gui.controller.object.gestion;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.ApplicationContext;

import py.com.alfa.escriba.gui.config.EscribaGUIApplicationContextProvider;
import py.com.alfa.escriba.gui.controller.view.Permissions;
import py.com.alfa.escriba.gui.controller.view.View;
import py.com.alfa.escriba.gui.controller.view.ViewManager;
import py.com.alfa.escriba.gui.controller.view.referencia.TemplatesViewContext;
import py.com.alfa.escriba.gui.controller.view.referencia.TemplatesViewFragment;
import py.com.alfa.escriba.gui.dto.admin.TabRefDTO;
import py.com.alfa.escriba.gui.dto.gestion.TemplatesDTO;
import py.com.alfa.escriba.gui.dto.gestion.VariablesDTO;
import py.com.alfa.escriba.gui.services.Services;


public class TemplatesControllerObject {

	private List<TemplatesDTO> templates;
	private TemplatesDTO template;
	private ViewManager viewManager;
	private String titulo = "";
	private List<TabRefDTO> tiposTemplate;
	private List<TabRefDTO> tiposObjeto;
	private List<VariablesDTO> variables;
	
	public TemplatesControllerObject() {
		ApplicationContext ctx = EscribaGUIApplicationContextProvider.getContext();
		this.setTemplates(new ArrayList<TemplatesDTO>());
		this.setViewManager((ViewManager) ctx.getBean(Services.VIEW_MANAGER));
		this.getViewManager().registerContext(View.TEMPLATES, new TemplatesViewContext());
	}

	public TemplatesViewFragment view(){
		return (TemplatesViewFragment) this.getContext().getViewFragment();
	}

	public TemplatesViewContext getContext(){
		return (TemplatesViewContext) getViewManager().getContext(View.TEMPLATES);
	}
	
	public Permissions getPermissions(){
		return getViewManager().getPermissions();
	}

	public List<TemplatesDTO> getTemplates() {
		return templates;
	}

	public void setTemplates(List<TemplatesDTO> templates) {
		this.templates = templates;
	}

	public TemplatesDTO getTemplate() {
		if ( this.template == null ) {
			this.template = new TemplatesDTO();
		}
		return template;
	}

	public void setTemplate(TemplatesDTO template) {
		this.template = template;
	}

	public ViewManager getViewManager() {
		return viewManager;
	}

	public void setViewManager(ViewManager viewManager) {
		this.viewManager = viewManager;
	}

	public String getTitulo() {
		return titulo;
	}

	public void setTitulo(String titulo) {
		this.titulo = titulo;
	}

	public List<TabRefDTO> getTiposTemplate() {
		return tiposTemplate;
	}

	public void setTiposTemplate(List<TabRefDTO> tiposTemplate) {
		this.tiposTemplate = tiposTemplate;
	}

	public List<TabRefDTO> getTiposObjeto() {
		return tiposObjeto;
	}

	public void setTiposObjeto(List<TabRefDTO> tiposObjeto) {
		this.tiposObjeto = tiposObjeto;
	}

	public List<VariablesDTO> getVariables() {
		return variables;
	}

	public void setVariables(List<VariablesDTO> variables) {
		this.variables = variables;
	}

}
